
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author ahmet
 */
public class WarningSystem {

    private static boolean isWindows() {
        return (System.getProperty("os.name").toLowerCase().indexOf("windows")!=-1);
    }

    private static boolean isLinux() {
        return (System.getProperty("os.name").toLowerCase().indexOf("linux")!=-1);
    }

    public static void popup(String message) {
        //Here we construct a popup window
        //and show on the computer screen
        final JDialog popupWindow = new JDialog();
        popupWindow.setTitle("Posture Correction Warning");
        popupWindow.setSize(300, 100);
        popupWindow.getContentPane().setLayout(new BorderLayout());

        JLabel warningLabel = new JLabel(message, JLabel.CENTER);

        JPanel jp = new JPanel(new FlowLayout());
        JButton closeButton = new JButton("Close");
        closeButton.setMnemonic('C');
        closeButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                popupWindow.dispose();
            }
        });
        jp.add(closeButton);

        popupWindow.getContentPane().add(warningLabel, BorderLayout.CENTER);
        popupWindow.getContentPane().add(jp, BorderLayout.SOUTH);

        popupWindow.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        popupWindow.setAlwaysOnTop(true);
        popupWindow.setVisible(true);
    }

    public static void sound() {
        Toolkit.getDefaultToolkit().beep();
    }

    public static void logout() {
        Runtime rt = Runtime.getRuntime();
        try {
            if (isWindows()){
                rt.exec("shutdown -l");
            } else if (isLinux()) {
                rt.exec("logout");
            }
        } catch(IOException e) {
            e.printStackTrace();
        }
    }

    public static void shutdown() {
        Runtime rt = Runtime.getRuntime();
        try {
            if (isWindows()){
                rt.exec("shutdown");
            } else if (isLinux()) {
                rt.exec("shutdown -h now");
            }
        } catch(IOException e) {
            e.printStackTrace();
        }
    }

    public static void lockMouse() {

    }

    public static void lockKeyboard() {

    }

    public static void lockKeyboardAndMouse() {

    }
}
